angular.module('mamApp').controller('editChannelModalController', ['$scope', 'PlayControlManager','$uibModalInstance','param','$state',
    function ($scope, PlayControlManager, $uibModalInstance,param,$state) {
        $scope.table = JSON.parse(localStorage.getItem("codeTable"));

        $scope.clientTypes = [
            {key: 501, value: $scope.table[501]},
            {key: 502, value: $scope.table[502]},
            {key: 503, value: $scope.table[503]},
            {key: 504, value: $scope.table[504]},
            {key: 505, value: $scope.table[505]},
            {key: 506, value: $scope.table[506]},
            {key: 507, value: $scope.table[507]},
            {key: 508, value: $scope.table[508]},
            {key: 509, value: $scope.table[509]}
        ];

        $scope.formData={};
        $scope.name=param.channel.name;
        $scope.clientType=parseInt(param.channel.clientType);
        $scope.id=param.channel.id;
        $scope.nameCheck=false;
        $scope.message="";
        $scope.clientType=param.channel.clientType;
        console.log($scope.clientType)
        $scope.cancel = function () {
            $uibModalInstance.dismiss("cancel");
        };

        $scope.table = JSON.parse(localStorage.getItem("codeTable"));

        $scope.submit = function() {

            var id = $scope.id;
            $scope.formData.name=$scope.name;
            $scope.formData.clientType=$scope.clientType;
            PlayControlManager.playChannelEdit(id,$scope.formData).then(function (result) {
                if(result.data.c=="s"){
                    $uibModalInstance.close($scope.data);
                    $state.go('main.playPlan.playChannel.playChannelDetail',{'clientType':$scope.formData.clientType},{reload:true})
                }else{
                    $scope.nameCheck=true;
                    $scope.message=result.data.i;
                }
            })
        }
    }])

